import router from "@/router";
import EventChannel from "./EventChannel";

// 页面级缓存事件
router.afterEach((to,from)=>{
    // 上一页面实例
    const fromCom = from.matched.at(-1)?.instances.default
    const instances = to.matched.at(-1).instances
    // 必须通过代理方式获取下一页实例
    to.matched.at(-1).instances = new Proxy(instances,{
        set(...arg){
            arg[2].$eventChannel = fromCom?.$eventChannel || new EventChannel({ once:true })
            // arg[2].$once('hook')
            return Reflect.set(...arg)
        },
    })
})